{extend name="public:base"}
{block name="body"}
<body class="pear-container">
	<form class="layui-form layui-form-pane" action="">
        <div class="mainBox">
            <div class="main-container">
                <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">角色名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" value="{$info.name|default=''}" lay-verify="require" autocomplete="off"
                                placeholder="请输入标题" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">上级角色</label>
                        <div class="layui-input-block">
                            <select name="pid" lay-verify="require">
                                {volist name="auth_group" id="vo"}
                                <option value="{$vo.id}" {present name="info.id"} {eq name="info.pid" value="$vo['id']"} selected {/eq} {/present}>{$vo.showName}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm6 layui-col-md4">
                    <div class="layui-form-item">
                        <label class="layui-form-label">描述</label>
                        <div class="layui-input-block">
                            <input type="text" name="description" value="{$info.description|default=''}"  autocomplete="off"
                                placeholder="请输入描述" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <div class="layui-form-item">
                        <label class="layui-form-label">权限列表</label>
                    </div>
                </div>
                <div class="layui-col-xs12 layui-col-sm12">
                    <div id="organizationTreeContent" style="overflow: auto">
                        <ul id="organizationTree" class="dtree organizationTree" data-id="0"></ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="bottom">
            <div class="button-container">
                <input type="hidden" name="rules" value="{$info.rules|default=''}">
                <input type="hidden" name="id" value="{$info.id|default=''}">
                <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="" lay-filter="form-save">
                    <i class="layui-icon layui-icon-ok"></i> 提交
                </button>
                <button type="reset" class="pear-btn pear-btn-sm">
                    <i class="layui-icon layui-icon-refresh"></i>
                    重置
                </button>
            </div>
        </div>
    </form>
</body>
{/block}
{block name="custom"}{/block}
{block name="script"}
<script>
    layui.use(['form', 'jquery', 'common','dtree'], function() {
        let form = layui.form;
        let $ = layui.jquery;
        let dtree = layui.dtree;
        var DTree = dtree.render({
            elem: "#organizationTree",
            data: {$node},
            dataFormat:"list",
            checkbar:true,
            initLevel: 1,
            icon: "-1",
            skin: "layui",
            checkbarFun:{
                chooseDone: function(checkbarNodesParam) { //复选框点击事件完毕后，返回该树关于复选框操作的全部信息。
                    console.log(checkbarNodesParam);
                    if (checkbarNodesParam.length === 0) {
                        return "";
                    }
                    let ids = "";
                    for (let i = 0; i < checkbarNodesParam.length; i++) {
                        ids += checkbarNodesParam[i].nodeId + ",";
                    }
                    ids = ids.substr(0, ids.length - 1);
                    $('input[name="rules"]').val(ids);
                }
            }
            
        });
        form.on('submit(form-save)', function(data) {
            $.ajax({
                url: '{:url("edit")}',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function(result) {
                    if (result.code == '1') {
                        layer.msg(result.msg, {
                            icon: 1,
                            time: 1000
                        }, function() {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("table-list");
                        });
                    } else {
                        layer.msg(result.msg, {
                            icon: 2,
                            time: 1000
                        });
                    }
                }
            })
            return false;
        });
    })
</script>
{/block}